import { createPinia } from "pinia";
import piniaPersist from "pinia-plugin-persist";

// 创建 Pinia
const pinia = createPinia();

// 支持 pinia 访问内部的 $reset
pinia.use(({ store }) => {
  const initialState = JSON.parse(JSON.stringify(store.$state));

  store.$reset = () => {
    store.$state = JSON.parse(JSON.stringify(initialState));
  };
});

// 持久化设置
pinia.use(piniaPersist);

export default pinia;
